﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PlanningGIS.ManageUtility;
using PlanningGIS.ManageUtility.Modules;
using PlanningGIS.Win.Controls;

namespace PlanningGIS.Manager
{
    /// <summary>
    /// TOC配置管理
    /// </summary>
    public partial class CtlToc : UserControl
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        public CtlToc()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 
        /// </summary>
        private BillCommands _Commands;
        /// <summary>
        /// 获取或设置功能操作的按钮
        /// </summary>
        public BillCommands Commands
        {
            get { return _Commands; }
            set
            {
                if (value != _Commands)
                {
                    BillCommands oldValue = _Commands;
                    _Commands = value;
                    OnCommandsChanged(oldValue, value);
                }
            }
        }

        /// <summary>
        /// 按钮改变事件
        /// </summary>
        /// <param name="oldCmd">Old property value</param>
        /// <param name="newCmd">New property value</param>
        protected virtual void OnCommandsChanged(BillCommands oldCmd, BillCommands newCmd)
        {
            btnSave.Command = newCmd != null ? newCmd.TocCommands.Save : null;
            btnCancel.Command = newCmd != null ? newCmd.TocCommands.Cancel : null;
        }

        /// <summary>
        /// 加载控件
        /// </summary>
        public void LoadControl()
        {
            try
            {
                ctlFuncCfg1.InitControl(2);
                Hash_Table ht = ManageHelper.GetHash_Table(ManageHelper.KEY_TOC);
                if (ht != null)
                {
                    ctlFuncCfg1.ReadXml(Encoding.UTF8.GetString(ht.Value));
                }
            }
            catch (Exception ex)
            {
                MsgHelper.ShowErrorMsgbox(ex.Message);
            }
        }

        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, EventArgs e)
        {
            ctlFuncCfg1.Save(ManageHelper.KEY_TOC);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCancel_Click(object sender, EventArgs e)
        {

        }

    }
}
